home *** CD-ROM | disk | FTP | other *** search
- #include <MacIncludes.h>
-
- #define MARGINS 20
-
-
- THPrint gPrinterRecord;
- TPPrPort gPrinterPort;
-
-
- void PrintText(TEHandle hTE)
- {
-
- int totalLines;
- Rect rView;
- GrafPtr oldPort;
- Rect oldView;
- Rect oldDest;
- int totalHeight;
- int currentLine;
- int scrollAmount;
- Rect zeroRect={ 0,0,0,0 };
- TPrStatus thePrinterStatus;
- Boolean OpenPrintManager;
- Boolean abort;
- int viewHeight;
-
-
- OpenPrintManager = false;
- if (gPrinterRecord){
- PrOpen();
- if (PrJobDialog( gPrinterRecord )){
- GetPort( &oldPort );
- oldView = (*hTE)->viewRect;
- oldDest = (*hTE)->destRect;
- gPrinterPort = PrOpenDoc( gPrinterRecord, nil, nil );
- OpenPrintManager = ( PrError() == noErr );
- }
- }
-
- if (OpenPrintManager){
- SetPort( (GrafPtr) gPrinterPort);
- rView = (*gPrinterRecord)->prInfo.rPage;
- InsetRect( &rView, MARGINS, MARGINS );
- (*hTE)->inPort = (GrafPtr)gPrinterPort;
- (*hTE)->destRect = rView;
- (*hTE)->viewRect = rView;
- TECalText(hTE);
- totalLines = (*hTE)->nLines;
- totalHeight = TEGetHeight(totalLines, 0, hTE);
- (*hTE)->destRect.bottom = (*hTE)->destRect.top + totalHeight;
-
- abort = false;
- currentLine = 1;
-
- while(!abort&& (currentLine <= totalLines)){
- PrOpenPage( gPrinterPort, nil );
- scrollAmount = 0;
- ClipRect( &(*gPrinterRecord)->prInfo.rPage );
- viewHeight = (*hTE)->viewRect.bottom - (*hTE)->viewRect.top + 1;
- while ((( scrollAmount + TEGetHeight( currentLine, currentLine, hTE ) ) <= viewHeight )
- && ( currentLine <= totalLines ) ){
- scrollAmount = scrollAmount + TEGetHeight( currentLine, currentLine, hTE );
- currentLine = currentLine + 1;
- }
-
- (*hTE)->viewRect.bottom = scrollAmount + MARGINS;
- TEDeactivate( hTE );
- TEUpdate( &(*hTE)->viewRect, hTE );
- ClipRect( &zeroRect );
- TEScroll( 0, -scrollAmount, hTE );
- (*hTE)->viewRect.bottom = rView.bottom;
- if (PrError() == iPrAbort){
- abort = true;
- }
- PrClosePage( gPrinterPort );
- }
-
- PrCloseDoc( gPrinterPort );
- if (((*gPrinterRecord)->prJob.bJDocLoop == bSpoolLoop ) && ( PrError == noErr )){
- PrPicFile( gPrinterRecord, nil, nil, nil, &thePrinterStatus );
- }
- PrClose();
- SetPort( oldPort );
- (*hTE)->inPort = oldPort;
- (*hTE)->viewRect = oldView;
- (*hTE)->destRect = oldDest;
- TEUpdate( &oldView, hTE );
- }
- }
-